package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.StoreConsumer;
import com.ruoyi.system.service.IStoreConsumerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商铺消费Controller
 * 
 * @author ruoyi
 * @date 2020-10-14
 */
@Controller
@RequestMapping("/system/consumer")
public class StoreConsumerController extends BaseController
{
    private String prefix = "system/consumer";

    @Autowired
    private IStoreConsumerService storeConsumerService;

    @RequiresPermissions("system:consumer:view")
    @GetMapping()
    public String consumer()
    {
        return prefix + "/consumer";
    }

    /**
     * 查询商铺消费列表
     */
    @RequiresPermissions("system:consumer:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StoreConsumer storeConsumer)
    {
        startPage();
        List<StoreConsumer> list = storeConsumerService.selectStoreConsumerList(storeConsumer);
        return getDataTable(list);
    }

    /**
     * 导出商铺消费列表
     */
    @RequiresPermissions("system:consumer:export")
    @Log(title = "商铺消费", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StoreConsumer storeConsumer)
    {
        List<StoreConsumer> list = storeConsumerService.selectStoreConsumerList(storeConsumer);
        ExcelUtil<StoreConsumer> util = new ExcelUtil<StoreConsumer>(StoreConsumer.class);
        return util.exportExcel(list, "consumer");
    }

    /**
     * 新增商铺消费
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商铺消费
     */
    @RequiresPermissions("system:consumer:add")
    @Log(title = "商铺消费", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StoreConsumer storeConsumer)
    {
        return toAjax(storeConsumerService.insertStoreConsumer(storeConsumer));
    }

    /**
     * 修改商铺消费
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        StoreConsumer storeConsumer = storeConsumerService.selectStoreConsumerById(id);
        mmap.put("storeConsumer", storeConsumer);
        return prefix + "/edit";
    }

    /**
     * 修改保存商铺消费
     */
    @RequiresPermissions("system:consumer:edit")
    @Log(title = "商铺消费", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StoreConsumer storeConsumer)
    {
        return toAjax(storeConsumerService.updateStoreConsumer(storeConsumer));
    }

    /**
     * 删除商铺消费
     */
    @RequiresPermissions("system:consumer:remove")
    @Log(title = "商铺消费", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(storeConsumerService.deleteStoreConsumerByIds(ids));
    }
}
